package com.sunshine.scw.base.dao.query;

import java.io.Serializable;

/**
 * 投影查询类
 * @author xiao
 * @version 1.0
 */
public final class QueryProjection implements Serializable {
	
	private static final long serialVersionUID = 6889834608583508384L;

	public static final int OP_SUM = 1, OP_COUNT = 2, OP_AVG = 3, OP_MIN = 4,
			OP_MAX = 5, OP_COUNT_DISTINCT = 6, OP_GROUP = 7;

	/**
	 * 属性名
	 */
	protected String property;
	
	/**
	 * 操作运算符
	 */
	protected int operator;

	public QueryProjection() {
	}

	public QueryProjection(String property, int operator) {
		this.property = property;
		this.operator = operator;
	}

	/**
	 * 创建 "sum" 操作
	 */
	public static QueryProjection sum(String property) {
		return new QueryProjection(property, OP_SUM);
	}

	/**
	 * 创建 "group" 操作
	 */
	public static QueryProjection count(String property) {
		return new QueryProjection(property, OP_COUNT);
	}

	/**
	 * 创建 "avg" 操作
	 */
	public static QueryProjection avg(String property) {
		return new QueryProjection(property, OP_AVG);
	}

	/**
	 * 创建 "min" 操作
	 */
	public static QueryProjection min(String property) {
		return new QueryProjection(property, OP_MIN);
	}

	/**
	 * 创建 "max" 操作
	 */
	public static QueryProjection max(String property) {
		return new QueryProjection(property, OP_MAX);
	}

	/**
	 * 创建 "countDistinct" 操作
	 */
	public static QueryProjection countDistinct(String property) {
		return new QueryProjection(property, OP_COUNT_DISTINCT);
	}

	/**
	 * 创建 "group" 操作
	 */
	public static QueryProjection group(String property) {
		return new QueryProjection(property, OP_GROUP);
	}

	public String getProperty() {
		return property;
	}

	public int getOperator() {
		return operator;
	}

}
